home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 31 / Amiga Format CD31 (1998-09-02)(Future Publishing)(GB)(Track 1 of 2)[!][issue 1998-10].iso / -seriously_amiga- / hardware / transadf / source / read_disk.c < prev    next >
C/C++ Source or Header  |  1998-07-20  |  3KB  |  113 lines

  1. /* read_disk.c - Read a disk straight into a file
  2. ** Copyright (C) 1997,1998 Karl J. Ots
  3. ** 
  4. ** This program is free software; you can redistribute it and/or modify
  5. ** it under the terms of the GNU General Public License as published by
  6. ** the Free Software Foundation; either version 2 of the License, or
  7. ** (at your option) any later version.
  8. ** 
  9. ** This program is distributed in the hope that it will be useful,
  10. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12. ** GNU General Public License for more details.
  13. ** 
  14. ** You should have received a copy of the GNU General Public License
  15. ** along with this program; if not, write to the Free Software
  16. ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  17. */
  18.  
  19. #include <exec/types.h>
  20. #include <exec/memory.h>
  21. #include <dos/dos.h>
  22. #include <clib/exec_protos.h>
  23. #include <clib/dos_protos.h>
  24.  
  25. #include "read_disk.h"
  26. #include "main.h"
  27. #include "mem_chunks.h"
  28. #include "td.h"
  29. #include "util.h"
  30. #include "errors.h"
  31.  
  32.  
  33. #define RD_TBTRACKS 1                           /* Tracks in rd_TrackBuf */
  34. #define RD_TBSIZE   (RD_TBTRACKS * TRACK_SIZE)  /* Bytes in rd_TrackBuf  */
  35.  
  36. UBYTE *rd_TrackBuf;    /* Our input buffer - reads from disk. */
  37.  
  38.  
  39. /*
  40. ** Read a disk into a file.
  41. ** Expects all fields of adfPkt to be set.
  42. */
  43. void readDisk (struct ADF_Packet *adfPkt)
  44. {
  45.   BYTE TDError;
  46.   LONG DOSError, RWSize;
  47.   int i;
  48.   
  49.   
  50.   /* Output info header */
  51.   FPrintf (StdOut, "Reading from TrackDisk Unit %ld (DF%ld:) to %s.\n",
  52.                    adfPkt->diskUnit,
  53.                    adfPkt->diskUnit,
  54.                    adfPkt->ADFileName);
  55.   
  56.   FPrintf (StdOut, "Starting at track %ld, Ending at track %ld.\n",
  57.                    (adfPkt->startTrack>>1),
  58.                    (adfPkt->endTrack>>1));
  59.   
  60.   /* Allocate track buffer */
  61.   rd_TrackBuf = (UBYTE *) myAllocMem (RD_TBSIZE, MEMF_CLEAR);
  62.   if (!rd_TrackBuf)
  63.   {
  64.     /* Out of memory! */
  65.     FPrintf (StdErr, "%s: Out of memory.\n", ProgName);
  66.     cleanExit (RETURN_FAIL, ERROR_NO_FREE_STORE);
  67.   }
  68.   
  69.   /* Start reading */
  70.   for (i = adfPkt->startTrack; i <= adfPkt->endTrack; i++)
  71.   {
  72.     /* Check for Control-C break */
  73.     if (CTRL_C)
  74.     {
  75.       FPutC (StdOut, '\n');
  76.       FPrintf (StdErr, "%s - %s\n", breakText, ProgName);
  77.       cleanExit (RETURN_WARN, NULL);
  78.     }
  79.     
  80.     /* Update progress information */
  81.     FPuts (StdOut, "\rReading ");
  82.     FPUTS_TS (i, StdOut);
  83.     Flush (StdOut);
  84.     
  85.     /* Fill the buffer from disk */
  86.     TDError = readTrack (rd_TrackBuf, RD_TBTRACKS, i, adfPkt->diskReq);
  87.     if (TDError)
  88.     {
  89.       FPutC (StdOut, '\n');
  90.       FPrintf (StdErr, "%s: Error reading from DF%ld: - ", ProgName,
  91.                                                            adfPkt->diskUnit);
  92.       reportTDError (TDError);
  93.       cleanExit (RETURN_ERROR, NULL);
  94.     }
  95.     
  96.     /* Write the buffer to the output file */
  97.     RWSize = Write (adfPkt->ADFile, rd_TrackBuf, RD_TBSIZE);
  98.     if (RWSize != RD_TBSIZE)
  99.     {
  100.       DOSError = IoErr();
  101.       
  102.       FPutC (StdOut, '\n');
  103.       FPrintf (StdErr, "%s: Error writing to %s - ",ProgName,
  104.                                                     adfPkt->ADFileName);
  105.       reportDOSError (DOSError);
  106.       cleanExit (RETURN_ERROR, DOSError);
  107.     }
  108.   }
  109.   
  110.   /* Free buffer */
  111.   myFreeMem (rd_TrackBuf);
  112. }
  113.